<?php
	
	date_default_timezone_set('Europe/Rome');

	if(isset($_GET['sAPP']) && !empty($_GET['sAPP'])) {
		$sAPP = $_GET['sAPP'];	
	} else {
		die('ERROR: App not defined');
	}

	require_once "../$sAPP/include/const.inc.php";
	require_once "../$sAPP/include/functions.php";
	require_once "auth.inc.php";
	require_once "conn.inc.php";
	
	fnGetValueFromGET(array('sField','sValue','sType','sAction','iResource','sAPP'));

	$sScript = fnCurrentScript();
	
	$iAccessLvl = fnGetAccessLvl();	
	
	if (is_allowed('edit', $iAccessLvl)) {
	
		switch ($sAction) {
			
			case "toggle":
				$sQuery = "UPDATE `resources` SET `$sField` = '$sValue' WHERE `id` = '$iResource'";
				$rResult = custom_mysql_query($sQuery);	
				$sOutput = fnJsonOutput($sScript, $sAction, '', 0);
				break;
			
			default:
				fnUpdateLog('ACTION NOT VALID', 0, 'resources', 'E');
				$sOutput = fnJsonOutput($sScript, $sAction, '', 101);
				break;
		
		}
		
	} else {
		fnUpdateLog('LOW RIGHTS', 0, 'resources', 'S');
		$sOutput = fnJsonOutput($sScript, $sAction, '', 999);
	
	}
	
	echo $sOutput;

?>